package com.wzh.yebServe.controller;

import com.wzh.yebServe.pojo.ResultBean;
import com.wzh.yebServe.pojo.Salary;
import com.wzh.yebServe.service.ISalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author wzh
 * @create 2022/11/22 14:03
 * @Description:
 */
@Api(tags = "SalaryController")
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有工资套账")
    @GetMapping("/")
    public List<Salary> getAllSalary(){
        return salaryService.list();
    }

    @ApiOperation(value = "添加工资套账")
    @PostMapping("/")
    public ResultBean addSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (salaryService.save(salary)){
            return ResultBean.success("添加成功");
        }
        return ResultBean.error("添加失败");
    }

    @ApiOperation(value = "删除工资套账")
    @DeleteMapping("/{id}")
    public ResultBean deleteSalary(@PathVariable Integer id){
        if (salaryService.removeById(id)){
            return ResultBean.success("删除成功");
        }
        return ResultBean.error("删除失败");
    }

    @ApiOperation(value = "更新工资套账")
    @PutMapping("/")
    public ResultBean updateSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return ResultBean.success("更新成功");
        }
        return ResultBean.error("更新失败");
    }

}